"""
file: test_expect.py
Author: 城下秋草
Date: 2024/12/9
Desc: 断言验证
"""
import re

from playwright.sync_api import sync_playwright, expect

playwright = sync_playwright().start()
browser = playwright.chromium.launch(
    headless=False,
    slow_mo=500,
    args=["--window-position=1024,-850"]
)
page = browser.new_page()
page.goto('https://demoqa.com/dynamic-properties')

page.reload()
expect(page.locator('#enableAfter')).to_be_enabled()

page.reload()
expect(page.locator('#visibleAfter')).to_be_visible()

expect(page.locator('#colorChange')).to_have_class(re.compile('text-danger'))

expect(page.locator('#colorChange')).to_have_text(re.compile('Color'))

page.reload()
expect(page.get_by_role('button')).to_have_count(3)

page.get_by_text('Forms').click()
page.get_by_text('Practice Form').click()

expect(page.get_by_placeholder('First Name')).to_be_editable()
page.get_by_placeholder('First Name').fill('城下秋草')

expect(page.get_by_text('Female')).not_to_be_checked()
page.get_by_text('Female').check()

expect(page.get_by_text('Reading')).not_to_be_checked()
page.get_by_text('Reading').check()

expect(page).to_have_url('https://demoqa.com/automation-practice-form')
expect(page).to_have_title('DEMOQA')